@model  FreeSqlQueryViewModel

<style asp-name="codemirror"></style>
<style asp-name="codemirror-addon-hint-show-hint"></style>
<script asp-name="codemirror" depends-on="admin" at="Foot"></script>
<script asp-name="codemirror-addon-selection-active-line" at="Foot"></script>
<script asp-name="codemirror-mode-javascript" at="Foot"></script>
<script asp-name="codemirror-mode-sql" at="Foot"></script>
<script asp-name="codemirror-addon-hint-sql-hint" at="Foot"></script>

<div class="mb-3">
    <div class="form-check">
        <input type="checkbox" class="form-check-input" asp-for="ReturnDocuments" checked="@Model.ReturnDocuments" />
        <label class="form-check-label" asp-for="ReturnDocuments">@T["Return Documents"]</label>
        <span class="hint dashed">@T["Check to return the corresponding documents."]</span>
    </div>
    <span class="hint">@T["When checked, the result has to be a list of document ids."]</span>
</div>

<div class="mb-3">
    <label asp-for="Query">@T["Query"]</label>
    <textarea asp-for="Query" rows="12" class="form-control"></textarea>
    <span class="hint">@T["The SQL query to execute."]</span>
</div>

<script at="Foot">
    $(function () {
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.Query)'), { mode: "text/x-pgsql",
            indentWithTabs: true, smartIndent: true, matchBrackets : true, lineNumbers: true, styleActiveLine: true, viewportMargin: Infinity,
            extraKeys: {"Ctrl-Space": "autocomplete"},
            hintOptions: {tables: {
              ContentItemIndex: ["DocumentId"]
            }} });
    });
</script>
